package com.cookman.gameobjects.decks;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.cookman.assets.AssetMap;
import com.cookman.assets.AssetsImpl;
import com.cookman.assets.AssetsLocator;
import com.cookman.gameobjects.DiseaseCardActor;
import com.cookman.gameobjects.controls.ModalPopup;
import com.cookman.world.entities.Disease;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Cookman on 12.09.14.
 */
public class DiseaseDeckActor extends ModalPopup {

    private Sprite background = AssetsLocator.getSpriteByAtlasRegion(AssetsImpl.MAP, AssetMap.CARDBACKGROUND);
    private List<DiseaseCardActor> diseaseActors;

    public DiseaseDeckActor() {
        super();
    }

    private float padding = 0.2f;
    protected float scale = 1.2f;

    @Override
    public void draw(Batch batch, float parentAlpha) {
        batch.draw(background, this.getX(), this.getY(), this.getWidth(), this.getHeight());
        super.draw(batch, parentAlpha);
    }

    public void setDiseases(List<Disease> diseases) {
        float startX = 0.2f;
        clearChildren();
        addAcceptCancel();
        diseaseActors = new ArrayList<>();
        List<String> colors=new ArrayList<>();
        if (diseases != null)
            for (Disease disease : diseases) {
                if(colors.contains(disease.getColor())) continue;
                DiseaseCardActor actor = new DiseaseCardActor(disease, this);
                actor.setX(startX);
                actor.setY(this.getY());
                actor.setBounds(startX, this.getY(), scale, scale);
                startX += padding + actor.getWidth();
                addActor(actor);
                diseaseActors.add(actor);
                colors.add(disease.getColor());
            }
    }

    public void resetSelection() {
        if (diseaseActors != null) {
            for (DiseaseCardActor diseaseActor : diseaseActors) {
                diseaseActor.setIsSelected(false);
            }
        }
    }

    @Override
    public void renderShape(ShapeRenderer shapeRenderer) {

    }
}
